package cn.kgc.springloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author mosin
 * date 2022/1/5
 * @version 1.0
 */
@RestController
public class HystrixController {

    @GetMapping("/h1")
    public String test01(){
        return "Hystrix service ok";
    }

    @GetMapping("/h2")
    @HystrixCommand(fallbackMethod = "fallbackMethod01")
    public String test02(Integer id){
        if(id<0){
            throw new RuntimeException("参数不合法");
        }
        return "Hystrix service ok";
    }

    public  String  fallbackMethod01(Integer id){
        return "出现异常，当前服务被熔断！"+id;
    }
}
